package com.sky.controller.admin;


import com.sky.context.BaseContext;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Api(tags = "分类管理相关接口")
@RestController
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 分类分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> categoryPage(CategoryPageQueryDTO dto){
        log.info("分类分页查询：{}",dto);
        PageResult pageResult = categoryService.page(dto);
        return Result.success(pageResult);
    }

    /**
     * 新增分类
     * @param dto
     * @return
     */
    @PostMapping
    public Result categoryAdd(@RequestBody CategoryDTO dto){
        log.info("新增分类：{}",dto);
        categoryService.categoryAdd(dto);
        return Result.success();
    }

    /**
     * 修改分类
     * @param dto
     * @return
     */
    @PutMapping
    public Result categoryUpdate(@RequestBody CategoryDTO dto){
        log.info("修改分类：{}",dto);
        categoryService.categoryUpdate(dto);
        return Result.success();
    }

    @DeleteMapping
    public Result categoryDelete(Long id){
        log.info("删除分类：{}",id);
        categoryService.categoryDelete(id);
        return Result.success();
    }

    /**
     * 分类启用禁用接口
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result enableDisable(@PathVariable("status") Integer status,Long id){
        categoryService.enableDisable(status,id);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<Category>> list(Integer type){
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }
}
